<?php
namespace Todo\Controller;

/**
 * Class SpaceController
 * 个人中心（空间）模块基类控制器
 * @package Admin\Controller
 */
class SpaceController extends BaseController {

    /**
     * 初始化，完成配置加载， 用户确认，菜单加载
     */
    protected function _initialize(){

        parent::_initialize();

        $this->_loadUser(true);

    }

    /**
     * 通用分页查询，默认查询1000条
     * @param Model $model 模型对象
     * @param array $where 查询条件
     * @return array
     */
    protected function _list($model, $where){
        $this->_pager();
        $total = $model->pageCount($where);
        $list = $model->pageSelect($where, $this->_page, $this->_limit, $this->_order);
        return array(
            'list' => $list,
            'total' => $total
        );
    }

    /**
     * 设置grid的分页信息
     */
    protected  function _pager() {
        if (isset($_REQUEST['page']) && !empty($_REQUEST['page'])) {
            $this->_page = intval($_REQUEST['page']);
        }

        if (isset($_REQUEST['limit']) && !empty($_REQUEST['limit'])) {
            $this->_limit = intval($_REQUEST['limit']);
        }

        if (isset($_REQUEST['sort']) && !empty($_REQUEST['sort'])) {
            $this->_order = $_REQUEST['sort'];
            if (isset($_REQUEST['order']) && !empty($_REQUEST['order'])) {
                $this->_order .= ' ' . $_REQUEST['order'];
            }
        }
    }

}